home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / MouseModule / MouseModuleHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  5.1 KB  |  162 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        MouseModuleHeader.c
  3.  
  4.     Contains:    Mouse Module Header file
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17.  
  18. #include "MouseModule.h"
  19. #include "MouseModuleVersion.h"
  20.  
  21. static     OSStatus     MouseModuleInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  22. static     OSStatus     MouseModuleFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  23. static     OSStatus     MouseInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device);
  24. static     OSStatus    MouseNotifyProc(UInt32     notification, void *pointer, UInt32 refcon);
  25.  
  26. extern    usbMousePBStruct myMousePB;
  27. extern    usbMousePBStruct watchDogPB;
  28.  
  29. //------------------------------------------------------
  30. //
  31. //    This is the driver description structure that the expert looks for first.
  32. //  If it's here, the information within is used to match the driver
  33. //  to the device whose descriptor was passed to the expert.
  34. //    Information in this block is also used by the expert when an
  35. //  entry is created in the Name Registry.
  36. //
  37. //------------------------------------------------------
  38. USBDriverDescription    TheUSBDriverDescription = 
  39. {
  40.     // Signature info
  41.     kTheUSBDriverDescriptionSignature,
  42.     kInitialUSBDriverDescriptor,
  43.     
  44.     // Device Info
  45.     0,                                        // vendor = not device specific
  46.     0,                                        // product = not device specific
  47.     0,                                        // version of product = not device specific
  48.     kUSBMouseInterfaceProtocol,                // protocol = not device specific
  49.     
  50.     // Interface Info    (* I don't think this would always be required...*)                
  51.     0,                                        // Configuration Value
  52.     0,                                        // Interface Number
  53.     kUSBHIDInterfaceClass,                    // Interface Class
  54.     kUSBBootInterfaceSubClass,                 // Interface SubClass
  55.     kUSBMouseInterfaceProtocol,                // Interface Protocol
  56.         
  57.     
  58.     // Driver Info
  59.     kMouseModuleName kMouseStringVersShort,    // Driver name for Name Registry
  60.     kUSBHIDInterfaceClass,                    // Device Class  (from USBDeviceDefines.h)
  61.     kUSBBootInterfaceSubClass,                // Device Subclass 
  62.     kMouseHexMajorVers, 
  63.     kMouseHexMinorVers, 
  64.     kMouseCurrentRelease, 
  65.     kMouseReleaseStage,                        // version of driver
  66.     
  67.     // Driver Loading Info
  68.     kUSBProtocolMustMatch                    // Flags (currently undefined)
  69. };
  70.  
  71. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  72. {
  73.     kClassDriverPluginVersion,                // Version of this structure
  74.     0,                                        // Hardware Validation Procedure
  75.     MouseDeviceInitialize,                    // Initialization Procedure
  76.     MouseInterfaceInitialize,                // Interface Initialization Procedure
  77.     MouseModuleFinalize,                    // Finalization Procedure
  78.     MouseNotifyProc,                        // Driver Notification Procedure
  79. };
  80.     
  81.  
  82. // Initialization function
  83. // Called upon load by Expert
  84. static     OSStatus     MouseDeviceInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
  85. {
  86. #pragma unused (busPowerAvailable)
  87. #pragma unused (pDesc)
  88.     USBExpertStatus(device, kMouseModuleName": Entered via MouseDeviceInitialize! (ignored)", device);
  89.     return (OSStatus)noErr;
  90. }
  91.  
  92. // Interface Initialization Initialization function
  93. // Called upon load by Expert
  94. static     OSStatus     MouseInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device)
  95. {
  96.     InterfaceEntry(interfacenum, pInterface, pDesc, device);
  97.     ChainJADBProc();
  98.     return (OSStatus)noErr;
  99. }
  100.  
  101. static OSStatus    MouseNotifyProc(UInt32     notification, void *pointer, UInt32 refcon)
  102. {
  103. #pragma unused (pointer)
  104. #pragma unused (refcon)
  105.  
  106. OSStatus        status = noErr; 
  107.  
  108.     switch (notification)
  109.     {
  110.         case kNotifyExpertTerminating:            // TCC <USB22>
  111.                 return(noErr);
  112.             break;
  113.         case kNotifyDriverBeingRemoved:
  114.             myMousePB.driverRemovalPending = true;
  115.             watchDogPB.driverRemovalPending = true;
  116.             
  117.             USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Notification that driver removal is pending...", notification);
  118.             if (myMousePB.pb.usbRefcon & kCompletionPending)
  119.             {
  120.                 USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Waiting for transaction to complete", myMousePB.pb.usbRefcon);
  121.                 if (myMousePB.pipeRef)
  122.                 {
  123.                     USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Aborting interrupt pipe", myMousePB.pipeRef);
  124.                     if (USBAbortPipeByReference(myMousePB.pipeRef) != noErr){
  125.                         myMousePB.pb.usbRefcon &=  ~kCompletionPending;   // don't expect the completion to be called either
  126.                     }
  127.                     myMousePB.intPipeAborted = true;
  128.                     myMousePB.pipeRef = nil;
  129.                 }
  130.                 status = kUSBDeviceBusy;
  131.             }
  132.             break;
  133.             
  134.         default:
  135.             break;
  136.     } // switch
  137.     
  138.     return(status);
  139. }
  140.  
  141.  
  142. // Termination function
  143. // Called by Expert when driver is being shut down
  144. static OSStatus MouseModuleFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  145. {
  146. #pragma unused (pDesc)
  147. //USBHIDData        theMouseData;
  148.  
  149.     USBExpertStatus(theDeviceRef, kMouseModuleName": Finalize", 0);
  150.     
  151.     if (myMousePB.pCursorDeviceInfo != 0)                
  152.     {
  153.         USBExpertStatus(theDeviceRef, kMouseModuleName": Removing CDM device", 0);
  154.         CursorDeviceDisposeDevice(myMousePB.pCursorDeviceInfo);
  155.         myMousePB.pCursorDeviceInfo = 0;
  156.     }
  157.     UnchainJADBProc();
  158.  
  159.     return (OSStatus)noErr;
  160. }
  161.  
  162.